package com.tanger.log;

import com.tanger.common.exception.AbstractController;
import com.tanger.common.jpa.PageParams;
import com.tanger.common.page.PageList;
import com.tanger.common.result.ActionResult;
import com.tanger.common.utils.StringUtil;
import com.tanger.log.config.OperateLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @Description 系统操作日志控制层
 * @Author Hchenbin
 * @Date 2024/01/08 16:28
 * @Version 1.0
 */
@RestController
@RequestMapping("/tanger/bts/log")
@Api(value = "系统操作日志",tags="系统操作日志")
public class SysLogController extends AbstractController{

    @Autowired
    private SysLogService service;

    @ApiImplicitParam(name = "id", value = "主键", required = true, paramType = "query" ,dataType = "Long")
    @ApiOperation(value = "获取操作记录详情")
    @GetMapping("/findOne")
    public ActionResult<SysLog> findOne(@RequestParam Long id){
        if (StringUtil.isNull(id)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findOne(id));
    }

    @ApiOperation(value = "分页查询操作记录")
    @PostMapping("/findAll")
    public ActionResult<PageList<SysLog>> findByUserId(@RequestBody PageParams query){
        if (Objects.isNull(query)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return ActionResult.buildResultSuccess(service.findAll(query));
    }

    @ApiOperation(value = "删除操作记录")
    @DeleteMapping("/delete")
    public ActionResult delete(@RequestParam List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return ActionResult.buildResultError("参数缺失");
        }
        return service.delete(ids);
    }

    @ApiOperation(value = "清空操作记录")
    @DeleteMapping("/clear")
    public ActionResult clear() {
        return service.clear();
    }
}

